﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TBM.Tools
{
    public class MailBoxNav:PageNavigation
    {
        /// <summary>
        /// 初始化导航条
        /// </summary>
        /// <param name="paramName">受参名</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="count">记录总数</param>
        /// <param name="displayPages">显示分页数</param>
        public MailBoxNav(string paramName, int pageSize, int count, int displayPages)
        {
            base.Init(paramName, pageSize, count, displayPages);
        }

        public MailBoxNav(string paramName, int pageSize, int displayPages)
        {
            base.Init(paramName, pageSize, 0, displayPages);
        }

        public string Create()
        {
            TextTemplate = TextTemplate.Replace(@"{count}", Count.ToString());
            TextTemplate = TextTemplate.Replace(@"{currpage}", _currPage.ToString());
            TextTemplate = TextTemplate.Replace(@"{pagesize}", PageSize.ToString());
            TextTemplate = TextTemplate.Replace(@"{currcount}", ((_currPage - 1) * PageSize + 1).ToString());
            TextTemplate = TextTemplate.Replace(@"{currpagecount}", (_currPage * PageSize).ToString());

            StringBuilder pageNav = new StringBuilder();

            // 上一页
            pageNav.AppendLine(
                String.Format(
                    "<a class=\"btn btn-sm blue{0}\" href=\"{1}\"><i class=\"fa fa-angle-left\"></i></a>",
                    _currPage == 1 ? " disabled" : "",
                    _currPage < 2 ? "javascript:void(0);" : CURL.GetURLByAddParam(QueryString, ParamName, (_currPage - 1).ToString())
                ));

            // 下一页
            pageNav.AppendLine(
                String.Format(
                    "<a class=\"btn btn-sm blue{0}\" href=\"{1}\"><i class=\"fa fa-angle-right\"></i></a>",
                    _currPage < PageCount ? "" : " disabled",
                    _currPage < PageCount ? CURL.GetURLByAddParam(QueryString, ParamName, (_currPage + 1).ToString()) : "javascript:void(0);"
                ));

            return pageNav.ToString();
        }
    }
}
